using NUnit.Framework;
using Tycho.Grammar;
using Tycho.Parser.Peg;

namespace Tycho.UnitTests.Grammar {
    [TestFixture]
    public class GrammarLoaderCreateNonTerminalSpecification {
        [Test]
        public void ShouldParseSequence () {
            IProduction production = GrammarLoader.CreateNonTerminal (IdentifierProduction.CreateTerminal ());

            ITerm t = production.ParseTerm ("tro {a+ 'keyword' b: lang c?}");
            Assert.IsNotNull (t);
            var expected =
                "non-terminal {name: 'tro', rule: sequence {rules: [one-or-more {rule: 'a'}, keyword {name: \"keyword\"}, capture {name: 'b', production: 'lang'}, optional {rule: 'c'}]}}";
            Assert.AreEqual (expected, t.ToString ());
        }

        [Test]
        public void ShouldParseChoice () {
            IProduction production = GrammarLoader.CreateNonTerminal(IdentifierProduction.CreateTerminal ());

            ITerm t = production.ParseTerm ("tri {a / b / c}");
            Assert.IsNotNull (t);
            var expected =
                "non-terminal {name: 'tri', rule: choice {choices: ['a', 'b', 'c']}}";
            Assert.AreEqual (expected, t.ToString ());
        }
    }
}